<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>C 结构体 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../w3cnote/c-structures-intro.html" />
<meta name="keywords" content="C 结构体">
<meta name="description" content="1、概述 C 语言允许用户自己指定这样一种数据结构，它由不同类型的数据组合成一个整体，以便引用，这些组合在一个整体中的数据是互相联系的，这样的数据结构称为结构体，它相当于其它高级语言中记录。 声明一个结构休类型的一般形式如下： struct 结构体名 {成员列表}; 结构体名，用作结构体类型的标志，它又称 结构体标记，大括号内是该结构体中的各个成员，由它们组成一个结构体，对各成员都应进行类型声明如：  类型名 成员名;  也可以成员列表..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<div class="container navigation">
    <div class="row">
        <div class="col nav">
            

                        <ul class="pc-nav" id="note-nav">
                <li><a href="../">首页</a></li>
                <li><a href="../w3cnote">笔记首页</a></li>
                <li><a href="../w3cnote/android-tutorial-intro.html" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" title="ES6 教程">ES6 教程</a></li>
                <li><a href="../w3cnote/ten-sorting-algorithm.html" title="排序算法">排序算法</a></li>
                <li><a href="../w3cnote/hadoop-tutorial.html" title="Hadoop 教程">Hadoop</a></li>
                <li><a href="../w3cnote/zookeeper-tutorial.html" title="Zookeeper 教程">Zookeeper</a></li>
                <li><a href="../w3cnote/verilog-tutorial.html" title="Verilog 教程">Verilog</a></li>
                <li><a href="../w3cnote_genre/code" title="编程技术">编程技术</a></li> 
                <li><a href="../w3cnote_genre/coderlife" title="程序员人生">程序员人生</a></li>
                
                <!--<li><a href="javascript:;" class="runoob-pop">登录</a></li>
                
                
                        <li>
                <a style="font-weight:bold;" href="../linux/linux-tutorial.html#yunserver" target="_blank" onclick="_hmt.push(['_trackEvent', 'aliyun', 'click', 'aliyun'])" title="kkb">云服务器</a>
                </li>
                <li><a href="http://gk.link/a/104mQ" target="_blank" style="font-weight: bold;"onclick="_hmt.push(['_trackEvent', '极客时间', 'click', 'jike'])" title="我的圈子">极客时间</a></li>
            
                
                <li><a target="_blank" href="../shoppinglist" rel="nofollow">知识店铺</a></li> 
        -->
            </ul>
                        
              
            <ul class="mobile-nav">
                <li><a href="../w3cnote">首页</a></li>
                <li><a href="../w3cnote_genre/android" target="_blank" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" target="_blank" title="ES6 教程">ES6</a></li>
                <li><a href="../w3cnote_genre/joke" target="_blank" title="程序员笑话">逗乐</a></li>
                
                <a href="javascript:void(0)" class="search-reveal">Search</a> 
            </ul>
            
        </div>
    </div>
</div>


<!--  内容  -->
<div class="container main">
	<div class="row">

		<div class="col middle-column big-middle-column">
	 			<div class="article">
			<div class="article-heading">
				<h2>C 结构体</h2>				<h3><em>分类</em> <a href="../w3cnote_genre/code" title="编程技术" >编程技术</a> </h3>
			</div>
			<div class="article-body note-body">
				<div class="article-intro">
					
<h2>1、概述</h2>
<p>C 语言允许用户自己指定这样一种数据结构，它由不同类型的数据组合成一个整体，以便引用，这些组合在一个整体中的数据是互相联系的，这样的数据结构称为结构体，它相当于其它高级语言中记录。</p>
<p>声明一个结构休类型的一般形式如下：</p>
<pre>struct 结构体名
{成员列表};</pre>
<p>结构体名，用作结构体类型的标志，它又称 结构体标记，大括号内是该结构体中的各个成员，由它们组成一个结构体，对各成员都应进行类型声明如：</p>

<pre>类型名 成员名;</pre>

<p>也可以成员列表称为域表，第一个成员也称为结构体中的一个域。成员名定名规则写变量名同。</p>
<pre>struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    float score;
    char addr[30];
};</pre>

<h2>
2、定义结构体类型变量的方法
</h2><p>
前面只是指定了一个结构体类型，它相当于一个模型，但其中并无具体数据，系统对之也不分配实际内存单元，为了能在程序中使用结构类型的数据，应当定义结构体类型的变量，并在其中存放具体的数据，可以采取以下3种方法定义结构体类型变量。</p>

<h3>（1）先声明结构体类型再定义变量名</h3>
<p>如上面已定义了一个结构体类型 struct student，可以用它来定义变量。如：</p>

<pre>struct student{  //结构体类型名
    ...
    ...
    ...
}student1, student2 //结构体变量名</pre>

<p>定义了 student1, student2 为 struct student 类型的变量。</p>

<p>在定义了结构体变量后，系统会为之分配内存单元。例如 student1 和 student2 在内存中各占 59 个字节。</p>
<p>应当注意，将一个变量定义为标准类型（基本数据类型）与定义为结构体类型不同之处在于后者不仅要求指定变量为结构体类型，而且要求指定为某一特定的结构体类型（例如 struct student 类型），因为可以定义出许多种具体的结构体类型。而在定义变量为整形时，只需指定为 int 型即可。</p>

<h3>（2）在声明类型的同时定义变量</h3>

<p>例如：</p>

<pre>struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    float score;
    char addr[30];
}student1, student2;</pre>

<p>它的作用与第一种方法相同，即定义了两个 struct student 类型的变量 student1, student2 这种形式的定义的一般形式为</p>

<pre>struct 结构体名
{
    成员表列
}变量名表列;</pre>
<h3>
（3）直接定义结构类型变量
</h3>
<p>其一般形式为:</p>
<pre>struct
{
    成员表列
}变量名表列;</pre>

<p>即不出现结构体名。</p>

<p>关于结构体类型，有几点要说明：</p>
<ul><li>
a. 类型与变量是不同的概念，不是混同，只能对变量赋值，存取或运算，而不能对一个类型赋值，存取或运算。在编译时，对类型是不分配空间的，只对变量分配空间。</li><li>
b. 对结构体中的成员（即 域）可以单元使用，它的作用与地位相当于普通变量。</li><li>
<p>c. 成员也可以是一个结构体变量。如：</p>



<pre>struct date // 声明一个结构体类型
{
    int month;
    int day;
    int year;
}

struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    struct date birthday;
    char addr[30];
}student1, student2;</pre>

<p>先声明一个 struct date 类型，它代表 日期 包括3个成员 month, day, year。然后在声明 struct student 类型时，将成员 birthday 指定为 struct date 类型。</p>
</li><li>
d. 成员名可以与程序中的变量名相同，二者不代表同一对象。</li></ul>
<hr><h2>3、结构体变量的引用</h2>

<p><strong>（1）不能将一个结构体变量作为一个整体进行输入和输出。</strong></p>

<p>只能对结构体变量中的各个成员分别进行输入输出。引用结构体变量中的成员的方式为：</p>
<pre>结构体变量名.成员名</pre>

<p>例如 student1.num 表示 student1 变量中的 num 成员，即 student1 的 num 项，可以对变量的成员赋值。例如：
student1.num = 10010;</p>

<p><span class="marked">.</span> 是成员（分量）运算符，它在所有的运算符中优先级最高，因此可以把 student1.num 作为一个整体来看待。上面的赋值语句作用是将整数 10010赋给 student1 变量中的成员 num。</p>

<p><strong>（2）如果成员本身又属一个结构体类型，则要用若干个成员运算符，一级一级地找到最低一级的成员。只能对最低的成员进行赋值或存取以及运算。</strong></p>

<p>例如：结构体变量 student1 可以这样访问各成员：</p>

<pre>student1.num
student1.birthday.month</pre>

<p>注意，不能用 student1.birthday 来访问 student1 变量中的成员 birthday，因为 birthday 本身是一个结构体变量。</p>

<p>（<strong>3）对结构体变量的成员可以像普通变量一样进行各种运算（根据其类型决定可以进行的运算）。</strong></p>

<pre>student2.score = student1.score;
sum = student1.score + student2.score;
student1.age ++;
++ student1.age;</pre>

<p>由于 <span class="marked">.</span> 运算符的优先级最高，因此 student1.age ++ 是对 student1.age 进行自加运算。而不是先对 age 进行自加运算。</p>

<p><strong>（4）可以引用结构体变量成员的地址。也可以引用结构体变量的地址。如：</strong></p>

<pre>scanf("%d", &amp;student1.num);// 输入 student1.num 的值
printf("%o", &amp;student1);// 输出 student1 的首地址</pre>

<p>但不能用以下语句整体读入结构体变量如：</p>

<pre>scanf("%d,%s,%c,%d,%f,%s", &amp;student1);</pre>

<p>结构体变量的地址主要用于作函数参数，传递结构体的地址。</p>



<hr><h2>4、结构体变量的初始化</h2>
和其它类型变量一样，对结构体变量可以在定义时指定初始值。

<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">long</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">sex</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">addr</span><span class="hl-brackets">[</span><span class="hl-number">30</span><span class="hl-brackets">]</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-brackets">{</span><span class="hl-number">89031</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Li Lin</span><span class="hl-quotes">&quot;</span><span class="hl-code">, '</span><span class="hl-identifier">M</span><span class="hl-code">', </span><span class="hl-quotes">&quot;</span><span class="hl-string">123 Beijing Road</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">NO. : %ld</span><span class="hl-special">\</span><span class="hl-string">nname: %s</span><span class="hl-special">\</span><span class="hl-string">nsex: %c</span><span class="hl-special">\</span><span class="hl-string">naddress: %s</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">sex</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">addr</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<hr><h2>5、结构体数组</h2>

<p>一个结构体变量中可以存放一组数据（如一个学生的学号，姓名，成绩等数据）。如果有10个学生的数据需要参加运算，显然应该用数组，这就是结构体数组。结构体数组与以前介绍过的数据值型数组不同之处在于每个数组元素都一个结构体类型的数据，它们分别包括各个成员（分量）项。</p>
<h3>
5.1 定义结构体数组
</h3><p>
和定义结构体变量的方法相仿，只需说明其为数组即可。</p>

<pre>struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    float score;
    char addr[30];
};
struct student stu[3];</pre>

<p>以上定义了一个数组 stu，其元素为 struct student 类型数据，数组有 3 个元素。也可以直接定义一个结构体数组。如：</p>

<pre>struct student
{
    int num;
    ....

}stu[3];

或

struct

{
    int num;
    　...
}stu[3];</pre>
<h3>
5.2 结构体数组的初始化
</h3><p>
与其它类型数组一样，对结构体数组可以初始化如：</p>

<pre>struct student
{
    int mum;
    char name[20];
    char sex;
    int age;
    float score;
    char addr[30];
}stu[3] = {{10101,"Li Lin", 'M', 18, 87.5, "103 Beijing Road"},
            {10101,"Li Lin", 'M', 18, 87.5, "103 Beijing Road"},
            {10101,"Li Lin", 'M', 18, 87.5, "103 Beijing Road"}};</pre>

<p>定义数组 stu 时，元素个数可以不指定，即写成以下形式：</p>

<pre>stu[] = {{...},{...},{...}};</pre>

<p>编译时，系统会根据给出初值的结构体常量的个数来确定数组元素的个数。</p>
<p>当然，数组的初始化也可以用以下形式：</p>
<pre>struct student
{
    int num;
    ...
};
struct student stu[] = {{...},{...},{...}};</pre>

<p>即先声明结构体类型，然后定义数组为该结构体类型，在定义数组时初始化。</p>
<p>从以上可以看到，结构体数组初始化的一般形式是在定义数组的后面加上：</p>
<h3>
5.3 结构体数组应用举例
</h3><p>
下面例子说明结构体数组的定义和引用。</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">string.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdlib.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">person</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">count</span><span class="hl-code">;
 
</span><span class="hl-brackets">}</span><span class="hl-identifier">leader</span><span class="hl-brackets">[</span><span class="hl-number">3</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-brackets">{</span><span class="hl-brackets">{</span><span class="hl-quotes">&quot;</span><span class="hl-string">Li</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">}</span><span class="hl-code">,
            　</span><span class="hl-brackets">{</span><span class="hl-quotes">&quot;</span><span class="hl-string">Zhang</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">}</span><span class="hl-code">,
            　</span><span class="hl-brackets">{</span><span class="hl-quotes">&quot;</span><span class="hl-string">Fun</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">}</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">i</span><span class="hl-code">, </span><span class="hl-identifier">j</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">leader_name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-identifier">i</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-identifier">i</span><span class="hl-code">&lt;= </span><span class="hl-number">10</span><span class="hl-code">;</span><span class="hl-identifier">i</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">scanf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%s</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">leader_name</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-identifier">j</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">;</span><span class="hl-identifier">j</span><span class="hl-code">&lt;</span><span class="hl-number">3</span><span class="hl-code">;</span><span class="hl-identifier">j</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code">
            </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-identifier">strcmp</span><span class="hl-brackets">(</span><span class="hl-identifier">leader_name</span><span class="hl-code">, </span><span class="hl-identifier">leader</span><span class="hl-brackets">[</span><span class="hl-identifier">j</span><span class="hl-brackets">]</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-brackets">)</span><span class="hl-code"> == </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">
                </span><span class="hl-identifier">leader</span><span class="hl-brackets">[</span><span class="hl-identifier">j</span><span class="hl-brackets">]</span><span class="hl-code">.</span><span class="hl-identifier">count</span><span class="hl-code"> ++;
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-identifier">i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">;</span><span class="hl-identifier">i</span><span class="hl-code">&lt;</span><span class="hl-number">3</span><span class="hl-code">;</span><span class="hl-identifier">i</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code">
        </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%5s: %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">leader</span><span class="hl-brackets">[</span><span class="hl-identifier">i</span><span class="hl-brackets">]</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-identifier">leader</span><span class="hl-brackets">[</span><span class="hl-identifier">i</span><span class="hl-brackets">]</span><span class="hl-code">.</span><span class="hl-identifier">count</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">system</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">pause</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>运行结果如下：</p>

<pre>LI
Li
Fun
Zhang
Zhang
Fun
Li
Fun
Zhang
Li

   Li: 3
Zhang: 3
  Fun: 3</pre>
<hr><h2>
6、指向结构体类型数据的指针</h2>
<p>一个结构体变量的指针就是该变量所占据的内存段的起始地址，可以设一个指针变量，用来指向一个结构体变量，此时该指针变量的值是结构体变量的起始地址。指针变量也可以用来指向结构体数组中的元素。</p>
<h3>
6.1 指向结构体变量的指针
</h3><p>
指向结构体变量的指针的应用：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">string.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdlib.b</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">long</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">sex</span><span class="hl-code">;
    </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">score</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> </span><span class="hl-identifier">stu_1</span><span class="hl-code">;
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">p</span><span class="hl-code">;
    </span><span class="hl-identifier">p</span><span class="hl-code"> = &amp;</span><span class="hl-identifier">stu_1</span><span class="hl-code">;
    </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code"> = </span><span class="hl-number">89101</span><span class="hl-code">;
    </span><span class="hl-identifier">strcpy</span><span class="hl-brackets">(</span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Li Lin</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">sex</span><span class="hl-code"> = '</span><span class="hl-identifier">M</span><span class="hl-code">';
    </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-code"> = </span><span class="hl-number">89</span><span class="hl-number">.5</span><span class="hl-code">;
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">NO. :%ld</span><span class="hl-special">\</span><span class="hl-string">nname: %s</span><span class="hl-special">\</span><span class="hl-string">nsex:%c</span><span class="hl-special">\</span><span class="hl-string">nscore:%f</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">sex</span><span class="hl-code">, </span><span class="hl-identifier">stu_1</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">NO. :%ld</span><span class="hl-special">\</span><span class="hl-string">nname: %s</span><span class="hl-special">\</span><span class="hl-string">nsex:%c</span><span class="hl-special">\</span><span class="hl-string">nscore:%f</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-brackets">(</span><span class="hl-code">*</span><span class="hl-identifier">p</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-brackets">(</span><span class="hl-code">*</span><span class="hl-identifier">p</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-brackets">(</span><span class="hl-code">*</span><span class="hl-identifier">p</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">sex</span><span class="hl-code">, </span><span class="hl-brackets">(</span><span class="hl-code">*</span><span class="hl-identifier">p</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">system</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">pause</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>在主函数中声明了 struct student 类型，然后定义了一个 struct student 类型的变量，stu_1 同时又定义一个指针变量 p ，它指向一个 struct student 类型的数据，在函数的执行部分将结构体变量 stu_1 的起始地址赋给指针变量 p ，也就是使 p 指向 stu_1 然后对 stu_1 的各成员赋值，第二个 printf 函数也是用来输出 stu_1 各成员的值，但使用的是 (*p).num 这样的形式， (*p) 表示 p 指向的结构体变量，(*p).num 是 p 指向的结构体变量中的成员 num 。注意 *p 两侧的括弧不可省略，因为成员运算符 '.' 优先于 '*' 运算符，*p.num 就等价于 *(p.num)</p>

<p>运行结果如下：</p>

<pre>NO. :89101
name: Li Lin
sex:M
score:89.500000
NO. :89101
name: Li Lin
sex:M
score:89.500000</pre>

<p>可以看到两个 printf 输出的结果相同。</p>

<p>在C语言中，为了使用方便和使之直观，可以把 (*p).num 改用 p->num 来代替，它表示 *p 所指向的结构体变量中的 num 成员，同样，(*p).name 等价于 p-&gt;name。</p>

<p>也就是说以下三种形式等价：</p>
<ul><li>
a. <strong>结构体变量.成员名</strong></li><li>
b. <strong>(*p).成员名</strong></li><li>
c. <strong>p-&gt; 成员名</strong></li></ul>

<p>上面的最后一个 printf 函数输了项可以改写为:</p>
<pre>printf("NO. :%ld\nname: %s\nsex:%c\nscore:%f\n",p-&gt;num, p-&gt;name, p-&gt;sex, p-&gt;score);</pre>
<p>其中 <span class="marked">-&gt;</span> 称为指向运算符。</p>

<p>分析以下几种运算符:</p>
<ul><li>
p -&gt; n 得到 p 指向的结构体变量中的成员 n 的值</li><li>
p -&gt; n ++ 得到 p 指向的结构体变量中的成员 n 的值，用完值后使它加 1</li><li>
++p -&gt; n 得到 p 指向的结构体变量中的成员 n 的值使之加 1 （先加）</li></ul>
<h3>
6.2 指向结构体数组的指针
</h3>
<p>以前介绍过可以使用指向数组或数组元素的指针和指针变量，同样，对结构体数组及其元素也可以用指针变量来指向。</p>
<p>指向结构体数组的指针的应用。</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#inlcude</span><span class="hl-code"> &lt;</span><span class="hl-identifier">stdlib</span><span class="hl-code">.</span><span class="hl-identifier">h</span><span class="hl-code">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">sex</span><span class="hl-code">;
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">age</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> </span><span class="hl-identifier">stu</span><span class="hl-brackets">[</span><span class="hl-number">3</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-brackets">{</span><span class="hl-brackets">{</span><span class="hl-number">10101</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Li Lin</span><span class="hl-quotes">&quot;</span><span class="hl-code">, '</span><span class="hl-identifier">M</span><span class="hl-code">', </span><span class="hl-number">18</span><span class="hl-brackets">}</span><span class="hl-code">,
                        　</span><span class="hl-brackets">{</span><span class="hl-number">10102</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Zhang Fun</span><span class="hl-quotes">&quot;</span><span class="hl-code">, '</span><span class="hl-identifier">M</span><span class="hl-code">', </span><span class="hl-number">19</span><span class="hl-brackets">}</span><span class="hl-code">,
                        　</span><span class="hl-brackets">{</span><span class="hl-number">10103</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Wang Min</span><span class="hl-quotes">&quot;</span><span class="hl-code">, '</span><span class="hl-identifier">F</span><span class="hl-code">', </span><span class="hl-number">20</span><span class="hl-brackets">}</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">p</span><span class="hl-code">;
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">No.    name        sex        age</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-identifier">p</span><span class="hl-code">=</span><span class="hl-identifier">stu</span><span class="hl-code">; </span><span class="hl-identifier">p</span><span class="hl-code">&lt;</span><span class="hl-identifier">stu</span><span class="hl-code">+</span><span class="hl-number">3</span><span class="hl-code">;</span><span class="hl-identifier">p</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code">
        </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%5d %-20s %2c %4d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">sex</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">age</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">system</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">pause</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>运行结果如下：</p>

<pre>No.    name        sex        age
10101 Li Lin                M       18
10102 Zhang Fun        M       19
10103 Wang Min          F        20</pre>

<p><strong>注意以下两点：</strong></p>
（<p>1）如果 p 的初值为 stu，即指向第一个元素，则 p + 1 后指向下一个元素的起始地址。例如：</p>

    <p>(++p) -&gt; num 先使 p 自加 1 ，然后得到它指向的元素中的 num 成员的值（即10102）。</p><p>
    (p++) -&gt;num 先得到 p->num 的值（即10101），然后使 p 自加 1 ，指向 stu[1]。</p>
    <p>注意以上二者的不同。</p>

<p>（2）程序已定义了指针 p 为指向 struct student 类型数据的变量，它只能指向一个 struct student 型的数据（p 的值是 stu 数组的一个元素的起始地址），而不能指向 stu 数组元素中的某一成员，（即 p 的地址不能是成员地址）。例如，下面是不对的：</p>
<pre>p = &amp;stu[1].name</pre>

<p>编译时将出错。千万不要认为反正 p 是存放地址的，可以将任何地址赋给它。如果地址类型不相同，可以用强制类型转换。例如：</p>
<pre>p = (struct student *)&amp;stu[1].name;</pre>

<p>此时，在 p 中存放 stu[1] 元素的 name 成员的起始地址。</p>
<h3>
6.3 用结构体变量和指向结构体的指针作函数参数
</h3><p>
将一个结构体变量的值传递给另一个函数，有3个方法：</p>
<ul><li>
（1）用结构体变量的成员作参数，例如：用 stu[1].num 或 stu[2].name 作函数实参，将实参值传给形参。用法和用普通变量作实参是一样的，属于 值传递 方式。应当注意实参与形参的类型保持一致。</li><li>
（2）用结构体变量作参数。老版本的C系统不允许用结构体变量作实参，ANSI C取消了这一限制。但是用结构体变量作实参时，采取的是 值传递 的方式，将结构体变量所占的内存单元全部顺序传递给形参。形参也必须是同类型的结构体变量。在函数调用期间形参也要占用内存单元。这种传递方式在空间和时间上开销较大，如果结构体的规模很大时，开销是很可观的，此外由于采用值传递方式，如果在执行被调用函数期间改变了形参（也是结构体变量）的值，该值不能返回主调函数，这往往造成使用上的不便。因此一般较少用这种方法。</li><li>
（3）用指向结构体变量（或数组）的指针作实参，将结构体变量（或数组）的地址传给形参。</li></ul>

<p>用结构体变量作函数参数。</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#define</span><span class="hl-code"> </span><span class="hl-identifier">FORMAT</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">%d</span><span class="hl-special">\</span><span class="hl-string">n%s</span><span class="hl-special">\</span><span class="hl-string">n%f</span><span class="hl-special">\</span><span class="hl-string">n%f</span><span class="hl-special">\</span><span class="hl-string">n%f</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">3</span><span class="hl-brackets">]</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">print</span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> </span><span class="hl-identifier">stu</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-identifier">FORMAT</span><span class="hl-code">, </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code">, </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">1</span><span class="hl-brackets">]</span><span class="hl-code">, </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> </span><span class="hl-identifier">stu</span><span class="hl-code">;
    </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code"> = </span><span class="hl-number">12345</span><span class="hl-code">;
    </span><span class="hl-identifier">strcpy</span><span class="hl-brackets">(</span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Li Li</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-number">67</span><span class="hl-number">.5</span><span class="hl-code">;
    </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">1</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-number">89</span><span class="hl-code">;
    </span><span class="hl-identifier">stu</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-number">78</span><span class="hl-number">.6</span><span class="hl-code">;
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-identifier">stu</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>将上面改用指向结构体变量的指针作实参。</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#define</span><span class="hl-code"> </span><span class="hl-identifier">FORMAT</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">%d</span><span class="hl-special">\</span><span class="hl-string">n%s</span><span class="hl-special">\</span><span class="hl-string">n%f</span><span class="hl-special">\</span><span class="hl-string">n%f</span><span class="hl-special">\</span><span class="hl-string">n%f</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">name</span><span class="hl-brackets">[</span><span class="hl-number">20</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">3</span><span class="hl-brackets">]</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-identifier">stu</span><span class="hl-code"> = </span><span class="hl-brackets">{</span><span class="hl-number">12345</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Li Li</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-number">67</span><span class="hl-number">.5</span><span class="hl-code">, </span><span class="hl-number">89</span><span class="hl-code">, </span><span class="hl-number">78</span><span class="hl-number">.6</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">print</span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">p</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-identifier">FORMAT</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">name</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">1</span><span class="hl-brackets">]</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-identifier">print</span><span class="hl-brackets">(</span><span class="hl-code">&amp;</span><span class="hl-identifier">stu</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<hr><h2>
7、用指针处理链表</h2>
<h3>
7.1 链表概述
</h3><p>
链表是一种常见的重要的数据结构。它是动态地进行存储分配的一种结构。</p>
<p>链表有一个 头指针 变量，它存放一个地址，该地址指向一个元素，链表中每一个元素称为 结点，每个结点都应包括两个部分，一为用户需要用的实际数据，二为下一个结点的地址。可以看出，头指针 head 指向第一个元素，第一个元素又指向第二个元素，。。。。直到最后一个元素，该元素不再指向其他元素，它称为 表尾，它的地址部分放一个 NULL（表示 空地址）链表到此结束。</p>
<p>可以看到链表中各元素在内存中可以不是连续存放的，要找某一元素，必须先找到上一个元素，根据它提供的下一元素地址才能找到下一个元素。如果不提供 头指针 head 则整个链表无法访问。</p>
<p>可以看到。这种链表的数据结构，必须利用指针变量才能实现，即一个结点中应包含一个指针变量，用它存放下一结点的地址。</p>
<p>前面介绍了结构体变量，用它作链表中的结点是最合适的，一个结构体变量包含若干成员，这些成员可以是数值类型，字符类型，数组类型，也可以是指针类型，我们用这个指针类型成员来存放下一个结点的地址。例如可以设计这样一个结构体类型：</p>

<pre>struct student
{
    int num;
    float score;
    struct student *next;
};</pre>

<p>其中成员 num 和 score 用来存放结点中的有用数据（用户需要用到的数据），next 是指针类型成员，它指向 struct student 类型数据（这是 next 所在结构体类型）。一个指针类型的成员既可以指向其他类型的结构体数据，也可以指向自己所在的结构体类型的数据。现在 next 是 struct student 类型中的一个成员，它又指向 struct student 类型的数据。用这种方法就可以建立链表。</p>

<p>请注意：只是定义一个 struct student 类型，并未实际分配存储空间，只有定义了变量才分配内存单元。</p>
<h3>
7.2 简单链表
</h3>
<p>下面通过一个例子来说明如何建立和输出一个简单链表:</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdlib.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-prepro">#define</span><span class="hl-code"> </span><span class="hl-prepro">NULL</span><span class="hl-code"> </span><span class="hl-number">0</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">long</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">score</span><span class="hl-code">;
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">next</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code">, </span><span class="hl-identifier">b</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code">, *</span><span class="hl-identifier">head</span><span class="hl-code">, *</span><span class="hl-identifier">p</span><span class="hl-code">;
    </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code"> = </span><span class="hl-number">99101</span><span class="hl-code">; </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-code"> = </span><span class="hl-number">89</span><span class="hl-number">.5</span><span class="hl-code">;
    </span><span class="hl-identifier">b</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code"> = </span><span class="hl-number">99103</span><span class="hl-code">; </span><span class="hl-identifier">b</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-code"> = </span><span class="hl-number">90</span><span class="hl-code">;
    </span><span class="hl-identifier">c</span><span class="hl-code">.</span><span class="hl-identifier">num</span><span class="hl-code"> = </span><span class="hl-number">99107</span><span class="hl-code">; </span><span class="hl-identifier">c</span><span class="hl-code">.</span><span class="hl-identifier">score</span><span class="hl-code"> = </span><span class="hl-number">85</span><span class="hl-code">;</span><span class="hl-comment">//对结点的 num 和 score 成员赋值</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">head</span><span class="hl-code"> = &amp;</span><span class="hl-identifier">a</span><span class="hl-code">;</span><span class="hl-comment">//将结点 a 的起始地址赋给头指针 head</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">a</span><span class="hl-code">.</span><span class="hl-identifier">next</span><span class="hl-code"> = &amp;</span><span class="hl-identifier">b</span><span class="hl-code">;</span><span class="hl-comment">//将结点 b 的起始地址赋给 a 结点的 next 成员</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">b</span><span class="hl-code">.</span><span class="hl-identifier">next</span><span class="hl-code"> = &amp;</span><span class="hl-identifier">c</span><span class="hl-code">;
    </span><span class="hl-identifier">c</span><span class="hl-code">.</span><span class="hl-identifier">next</span><span class="hl-code"> = </span><span class="hl-prepro">NULL</span><span class="hl-code">;</span><span class="hl-comment">// c 结点的 next 成员不存放其他结点地址</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">p</span><span class="hl-code"> = </span><span class="hl-identifier">head</span><span class="hl-code">;</span><span class="hl-comment">//使 p 指针指向 a 结点</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-reserved">do</span><span class="hl-code">
    </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%ld %5.1f</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">)</span><span class="hl-code">;</span><span class="hl-comment">// 输出 p 指向的结点的数据</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">p</span><span class="hl-code"> = </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">next</span><span class="hl-code">;</span><span class="hl-comment">//使 p 指向下一结点</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-reserved">while</span><span class="hl-brackets">(</span><span class="hl-identifier">p</span><span class="hl-code"> != </span><span class="hl-prepro">NULL</span><span class="hl-brackets">)</span><span class="hl-code">;</span><span class="hl-comment">//输出完 c 结点后 p 的值为 NULL</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">system</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">pause</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>运行结果:</p>

<pre>99101  89.5
99103  90.0
99107  85.0</pre>
<h3>
7.3 处理动态链表所需的函数
</h3>
<p><strong>（1）malloc 函数</strong></p>

<pre>void *malloc(unsigned int size);</pre>
<p>作用是在内存的动态存储区中分配一个长度为 size 的连接空间。些函数的值（即返回值）是一个指向分配空间起始地址的指针（基类型为 void）。如果些函数未能成功地执行（例如内存空间不足）则返回空指针 NULL。</p>

<p><strong>（2）calloc 函数</strong></p>

<pre>void *calloc(unsigned n, unsigned size);</pre>

<p>其作用是在内存的动态区存储中分配 n 个长度为 size 的连续空间。函数返回一个指向分配空间起始地址的指针，如果分配不成功，返回 NULL。
用 calloc 函数可以为一维数组开辟动态存储空间， n 为数组元素个数，每个元素长度为 size。</p>    
<p><strong>（3）free 函数</strong></p>
<pre>void free(void *p);</pre>

<p>其作用是释放由 p 指向的内存区，使这部分内存区能被其它变量使用， p 是最后一次调用 calloc 或 malloc 函数时返回的值。free 函数无返回值。
请注意：以前的C版本提供的 malloc 和 calloc 函数得到的是指向字符型数据的指针。ANSI C 提供的 malloc 和 calloc 函数规定为 void * 类型。</p>
<h3>
7.4 建立动态链表</h3><p>
所谓建立动态链表是指在程序执行过程中从无到有地建立起一个键表，即一个一个地开辟结点和输入各结点数据，并建立起前后相链的关系。</p>

<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdlib.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-prepro">#define</span><span class="hl-code"> </span><span class="hl-prepro">NULL</span><span class="hl-code"> </span><span class="hl-number">0</span><span class="hl-prepro"></span><span class="hl-code">
</span><span class="hl-prepro">#define</span><span class="hl-code"> </span><span class="hl-identifier">LEN</span><span class="hl-code"> </span><span class="hl-reserved">sizeof</span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-brackets">)</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">long</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">score</span><span class="hl-code">;
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">next</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">;
 
</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">p1</span><span class="hl-code">, *</span><span class="hl-identifier">p2</span><span class="hl-code">, *</span><span class="hl-identifier">head</span><span class="hl-code">;
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num</span><span class="hl-code">;
    </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">score</span><span class="hl-code">;
    </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">n</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
 
    </span><span class="hl-identifier">head</span><span class="hl-code"> = </span><span class="hl-prepro">NULL</span><span class="hl-code">;
 
    </span><span class="hl-identifier">p1</span><span class="hl-code"> = </span><span class="hl-identifier">p2</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-brackets">)</span><span class="hl-identifier">malloc</span><span class="hl-brackets">(</span><span class="hl-identifier">LEN</span><span class="hl-brackets">)</span><span class="hl-code">;
 
    </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">please input num and score.</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">scanf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%d,%f</span><span class="hl-quotes">&quot;</span><span class="hl-code">, &amp;</span><span class="hl-identifier">p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code">, &amp;</span><span class="hl-identifier">p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">)</span><span class="hl-code">;
 
    </span><span class="hl-reserved">while</span><span class="hl-brackets">(</span><span class="hl-identifier">p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code"> != </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">n</span><span class="hl-code"> ++;
        </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-identifier">n</span><span class="hl-code"> == </span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code">
            </span><span class="hl-identifier">head</span><span class="hl-code"> = </span><span class="hl-identifier">p1</span><span class="hl-code">;
        </span><span class="hl-reserved">else</span><span class="hl-code">
            </span><span class="hl-identifier">p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">next</span><span class="hl-code"> = </span><span class="hl-identifier">p1</span><span class="hl-code">;
        </span><span class="hl-identifier">p2</span><span class="hl-code"> = </span><span class="hl-identifier">p1</span><span class="hl-code">;
        </span><span class="hl-identifier">p1</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-brackets">)</span><span class="hl-identifier">malloc</span><span class="hl-brackets">(</span><span class="hl-reserved">sizeof</span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">please input num and score.</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
 
        </span><span class="hl-identifier">scanf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">%d,%f</span><span class="hl-quotes">&quot;</span><span class="hl-code">, &amp;</span><span class="hl-identifier">p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code">, &amp;</span><span class="hl-identifier">p1</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-identifier">p2</span><span class="hl-code">-&gt;</span><span class="hl-identifier">next</span><span class="hl-code"> = </span><span class="hl-prepro">NULL</span><span class="hl-code">;
    </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">head</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">printlist</span><span class="hl-brackets">(</span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">head</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">p</span><span class="hl-code">;
    </span><span class="hl-identifier">p</span><span class="hl-code"> = </span><span class="hl-identifier">head</span><span class="hl-code">;
    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-identifier">head</span><span class="hl-code"> != </span><span class="hl-prepro">NULL</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">do</span><span class="hl-code">
        </span><span class="hl-brackets">{</span><span class="hl-code">
            </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">num=%d score=%f</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">num</span><span class="hl-code">, </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">score</span><span class="hl-brackets">)</span><span class="hl-code">;
            </span><span class="hl-identifier">p</span><span class="hl-code"> = </span><span class="hl-identifier">p</span><span class="hl-code">-&gt;</span><span class="hl-identifier">next</span><span class="hl-code">;
        </span><span class="hl-brackets">}</span><span class="hl-reserved">while</span><span class="hl-brackets">(</span><span class="hl-identifier">p</span><span class="hl-code"> != </span><span class="hl-prepro">NULL</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">struct</span><span class="hl-code"> </span><span class="hl-identifier">student</span><span class="hl-code"> *</span><span class="hl-identifier">head</span><span class="hl-code">;
    </span><span class="hl-identifier">head</span><span class="hl-code"> = </span><span class="hl-identifier">create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">printlist</span><span class="hl-brackets">(</span><span class="hl-identifier">head</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">system</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">pause</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p><strong>以下是对链表的各种操作</strong></p>

<p>打印链表:</p>

<pre>void printlist(struct student *head)
{
    struct student *p;
    p = head;

    if(head != NULL)
    {
        do 
        {
            printf("num=%d score=%5.2f\n", p-&gt;num, p-&gt;score);
            p = p-&gt;next;
        } while (p != NULL);
    }
    /* while(p -&gt; next != NULL)
    {
        printf("num=%d score=%f\n", p-&gt;num, p-&gt;score);
        p = p-&gt;next;
    }*/
}</pre>

删除节点:

<pre>struct student *delNode(struct student *head, int num)
{
    printf("delNode.\n");
    struct student *p1, *p2;
    if(head == NULL)
    {
        printf("The List is NULL.\n");
    }
    else
    {
        p1 = head;
        while(p1-&gt;next != NULL &amp;&amp; p1-&gt;num != num)
        {
            p2 = p1;
            p1 = p1-&gt;next;
        }
        if(p1-&gt;num == num)
        {
            if(p1 == head)
                head = p1-&gt;next;
            else
                p2-&gt;next = p1-&gt;next;
        }
        else
            printf("Can not find list num.\n");
    }
    return head;
}</pre>

<p>更新节点:</p>

<pre>struct student *update(struct student *head, int index, int num, float score)
{
    printf("update.\n");
    struct student *p;
    if(head == NULL)
    {
        printf("The List is NULL.\n");
    }
    else
    {
        p = head;
        while(p-&gt;next != NULL &amp;&amp; p-&gt;num != index)
        {
            p = p-&gt;next;
        }
        if(p-&gt;num == index)
        {
            p-&gt;num = num;
            p-&gt;score = score;
        }
        else
            printf("Can not find list index.\n");
    }
    return head;
}</pre>

<p>增加节点:</p>

<pre>struct student *add(struct student *head, int index, int num, float score)
{
    printf("add.\n");
    struct student *p1, *p2, *p3;
    if(head == NULL)
    {
        printf("The List is NULL.\n");
    }
    else
    {
        p1 = p2 = head;
        while(p1-&gt;next != NULL &amp;&amp; p1-&gt;num != index)
        {
            p1 = p1-&gt;next;
            p2 = p1;
        }
        if(p1-&gt;num == index)
        {
            p3 = (struct student *)malloc(LEN);
            p3-&gt;num = num;
            p3-&gt;score = score;

            if(p2-&gt;next == NULL)
            {
                p2-&gt;next = p3;
                p3-&gt;next = NULL;
            }
            else
            {
                p3-&gt;next = p2-&gt;next;
                p2-&gt;next = p3;   
            }
        }
        else
            printf("Can not find list index.\n");
    }
    return head;
}</pre>



<blockquote><p>原文链接：http://www.cnblogs.com/qkhhxkj/archive/2011/06/28/2091818.html</p>
<p>参考书籍：谭浩强老师《C程序设计》一书中关于结构体类型的章节。</p>
</blockquote>

				</div>
			</div>
			<div class="previous-next-links">
			<div class="previous-design-link">← <a href="../w3cnote/matplotlib-tutorial.html" rel="prev"> Matplotlib 教程</a> </div>
			<div class="next-design-link"><a href="../w3cnote/scrapy-detail.html" rel="next"> Scrapy 入门教程</a> →</div>
			</div>
			<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style=" padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='20936' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  20936;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 20936, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":20936},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
			<div class="article-heading-ad" id="w3cnote-ad728">
			<script async src=""></script>
			<!-- 移动版 自动调整 -->
			<ins class="adsbygoogle"
			     style="display:inline-block;min-width:300px;max-width:970px;width:100%;height:90px"
			     data-ad-client="ca-pub-5751451760833794"
			     data-ad-slot="1691338467"
			     data-ad-format="horizontal"></ins>
			<script>
			(adsbygoogle = window.adsbygoogle || []).push({});
			</script>
			</div>
			<style>
@media screen and (max-width: 768px) {
	#w3cnote-ad728 {
		display: none;
	}
}
p.note-author {
    border-bottom: 1px solid #ddd;
    font-size: 18px;
    font-weight: bold;
    color: #78a15a;
    padding-bottom: 2px;
    margin-bottom: 4px;
}
</style>
<script>
var aid = 20936;
</script>
	</div>
		
	</div>
	<div class="listcol last right-column">




<!--
	<div class="tab tab-light-blue"> 订阅</div>
	<div class="sidebar-box">
		<div class="socialicons">
			<a href="../feed" class="rss">RSS 订阅</a>
		
			<form action="//list.qq.com/cgi-bin/qf_compose_send" method="post">
			<input type="hidden" value="qf_booked_feedback" name="t">
			<input type="hidden" value="4b67b6b6c1f5e792559940cab4aebb8f1126fba880bff1a8" name="id">
			<input class="placeholder" id="feed_email" name="to" value="输入邮箱 订阅笔记" autocomplete="off">
			<input type="submit" value="订阅" class="btn btn-primary">
			</form>
		
		</div>
 
	</div>
-->	



<!--
	<div class="sidebar-box cate-list">
	<div class="sidebar-box recommend-here list-link">
			<a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;">笔记列表</a>
		</div>

 

</div>
-->

	 <div class="sidebar-box cate-list">
		 		

	 	<div class="sidebar-box recommend-here list-link">
			<a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;">教程列表</a>
		</div>
		
		<div class="cate-items"> 
				<a href="../ado">ADO 教程</a>
	<a href="../ajax">Ajax 教程</a>
	<a href="../android">Android 教程</a>
	<a href="../angularjs2">Angular2 教程</a>
	<a href="../angularjs">AngularJS 教程</a>
	<a href="../appml">AppML 教程</a>
	<a href="../asp">ASP 教程</a>
	<a href="../aspnet">ASP.NET 教程</a>
	<a href="../bootstrap">Bootstrap 教程</a>
	<a href="../bootstrap4">Bootstrap4 教程</a>
	<a href="../bootstrap5">Bootstrap5 教程</a>
	<a href="../cprogramming">C 教程</a>
	<a href="../csharp">C# 教程</a>
	<a href="../cplusplus">C++ 教程</a>
	<a href="../chartjs">Chart.js 教程</a>
	<a href="../cssref">CSS 参考手册</a>
	<a href="../css">CSS 教程</a>
	<a href="../css3">CSS3 教程</a>
	<a href="../django">Django 教程</a>
	<a href="../docker">Docker 教程</a>
	<a href="../dtd">DTD 教程</a>
	<a href="../echarts">ECharts 教程</a>
	<a href="../eclipse">Eclipse 教程</a>
	<a href="../firebug">Firebug 教程</a>
	<a href="../font-awesome">Font Awesome 图标</a>
	<a href="../foundation">Foundation 教程</a>
	<a href="../git">Git 教程</a>
	<a href="../go">Go 语言教程</a>
	<a href="../googleapi">Google 地图 API 教程</a>
	<a href="../highcharts">Highcharts 教程</a>
	<a href="../htmldom">HTML DOM 教程</a>
	<a href="../tags">HTML 参考手册</a>
	<a href="../charsets">HTML 字符集</a>
	<a href="../html">HTML 教程</a>
	<a href="../http">HTTP 教程</a>
	<a href="../ionic">ionic 教程</a>
	<a href="../ios">iOS 教程</a>
	<a href="../java">Java 教程</a>
	<a href="../jsref">JavaScript 参考手册</a>
	<a href="../js">Javascript 教程</a>
	<a href="../jeasyui">jQuery EasyUI 教程</a>
	<a href="../jquerymobile">jQuery Mobile 教程</a>
	<a href="../jqueryui">jQuery UI 教程</a>
	<a href="../jquery">jQuery 教程</a>
	<a href="../json">JSON 教程</a>
	<a href="../jsp">JSP 教程</a>
	<a href="../julia">Julia 教程</a>
	<a href="../kotlin">Kotlin 教程</a>
	<a href="../linux">Linux 教程</a>
	<a href="../lua">Lua 教程</a>
	<a href="../markdown">Markdown 教程</a>
	<a href="../matplotlib">Matplotlib 教程</a>
	<a href="../maven">Maven 教程</a>
	<a href="../memcached">Memcached 教程</a>
	<a href="../mongodb">MongoDB 教程</a>
	<a href="../mysql">MySQL 教程</a>
	<a href="../nodejs">Node.js 教程</a>
	<a href="../numpy">NumPy 教程</a>
	<a href="../pandas">Pandas 教程</a>
	<a href="../perl">Perl 教程</a>
	<a href="../php">PHP 教程</a>
	<a href="../postgresql">PostgreSQL 教程</a>
	<a href="../python3">Python 3 教程</a>
	<a href="../python">Python 基础教程</a>
	<a href="../r">R 教程</a>
	<a href="../rdf">RDF 教程</a>
	<a href="../react">React 教程</a>
	<a href="../redis">Redis 教程</a>
	<a href="../rss">RSS 教程</a>
	<a href="../ruby">Ruby 教程</a>
	<a href="../rust">Rust 教程</a>
	<a href="../sass">Sass 教程</a>
	<a href="../scala">Scala 教程</a>
	<a href="../scipy">SciPy 教程</a>
	<a href="../servlet">Servlet 教程</a>
	<a href="../soap">SOAP 教程</a>
	<a href="../sql">SQL 教程</a>
	<a href="../sqlite">SQLite 教程</a>
	<a href="../svg">SVG 教程</a>
	<a href="../svn">SVN 教程</a>
	<a href="../swift">Swift 教程</a>
	<a href="../tcpip">TCP/IP 教程</a>
	<a href="../typescript">TypeScript 教程</a>
	<a href="../vbscript">VBScript 教程</a>
	<a href="../vue2">Vue.js 教程</a>
	<a href="../vue3">Vue3 教程</a>
	<a href="../w3c">W3C 教程</a>
	<a href="../webservices">Web Service 教程</a>
	<a href="../wsdl">WSDL 教程</a>
	<a href="../xlink">XLink 教程</a>
	<a href="../dom">XML DOM 教程</a>
	<a href="../schema">XML Schema 教程</a>
	<a href="../xml">XML 教程</a>
	<a href="../xpath">XPath 教程</a>
	<a href="../xquery">XQuery 教程</a>
	<a href="../xslfo">XSLFO 教程</a>
	<a href="../xsl">XSLT 教程</a>
	<a href="../data-structures">数据结构</a>
	<a href="../regexp">正则表达式</a>
	<a href="../quiz">测验</a>
	<a href="../browsers">浏览器</a>
	<a href="../quality">网站品质</a>
	<a href="../web">网站建设指南</a>
	<a href="../hosting">网站服务器教程</a>
	<a href="../design-pattern">设计模式</a>
			
		</div> 
		 	 </div>
</div>
	</div>
</div>


<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>